$(function(){
	;(function (doc, win) {

        var docEl = doc.documentElement,
            resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
            oldW = '',clientWidth = '';
            recalc = function () {

                clientWidth = $(window).width();

                if (!clientWidth) return;

                if(oldW === clientWidth) return false;

                oldW = clientWidth;

                docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';

            };

        if (!doc.addEventListener) return;

        win.addEventListener(resizeEvt, recalc, false);

        recalc();
        //加载热搜此
        LoadHotSearch();
    })(document, window);


	$(".recommend-c").delegate(".recommend-tag","touchstart",function(e){

		e.preventDefault();

		/**
		 * 点击历史记录 
		 */
		if($(this).hasClass("recommend-tag")){

			$('.search-value').val( $(this).html() );

			return false;
		}
		return false;
	})

	/**
	 * 清空 input的值
	 */
	$(".clear-text").on("click",function(){

		$(".search-value").val('');

		return false;
	})
	/**
	 * 点击确定按钮进行搜索
	 */
	$(".search-btn").on("click",function(){

		//发送ajax 请求
		if(!$(".search-value").val()) return false;
		$(".sc-recommend").hide();
		//alert("发送ajax 请求");
        filmObject.pno=1;
        filmObject.text=$(".search-value").val();
        LoadSearchVideos();
		return false;
	})

	/**
	 * 监听 input 值的变化
	 */
	$(".search-value").on("input porpertychange",function(){

		var _v = $(this).val();

		!_v ? $(".clear-text").hide() :  $(".clear-text").show();

		return false;
	});
})

var filmObject = {
    pno: 1,
    pagesize: 9,
    allcount: -1,
    text:''
}
//获取热搜此
function  LoadHotSearch() {
    $.ajax({
        type: 'get',
        url:
            '/api/keyword/getkeywordlist?count=10',
        dataType: 'json',
        success: function(data){
            if (mortise_layout.ValidataResult(data)) {
                //{"code":"OperateOk","errorMsg":"","result":{"list":[{"fId":"594cabc05bc42d07a0aa541a","fName":"一个钓鱼的故事","fFilmtype":"1000010100000000000","fYear":2016,"fCountry":12,"fKeyword":"一个钓鱼的故事","fPhoto":"http://119.10.70.142:9080/Images/upload/videoPhoto/595a87fe37ca1d108069af15.png","fPhotow":"http://101.201.122.79:8083/Images/upload/videoPhoto/596adca774c36b070e69ec8e.jpg","fDirector":"Matt Birman","fPerformer":"Eddie McClintock, Jayne Heitmeyer, Jordyn Negri ","fShowtime":"2016-12-12","fScore":0.0,"fPricetagid":"0","fPricetagname":"免费电影","fIntime":"2017-06-23 14:20:23","fShow":1,"fLookct":0,"fMakelookct":11,"fGoodct":0,"fMakegoodct":12,"fCollect":2,"fMakecollect":13,"fPlayct":132,"fMakepalyct":15,"fSharect":0,"fMakesharect":null,"fBuyct":0,"fCommentct":22,"fSourceurl":null,"fCountryname":"加拿大","fFilmtypename":"喜剧/剧情/奇幻","fImpression":"印象"},{"fId":"5930e4cd1c886e2dc0d45342","fName":"末世迷踪：下一代","fFilmtype":"0000000100000000000","fYear":2016,"fCountry":4,"fKeyword":"末世迷踪：下一代","fPhoto":"http://119.10.70.142:9080/Images/upload/videoPhoto/595a88f137ca1d108069af17.png","fPhotow":"http://101.201.122.79:8083/Images/upload/videoPhoto/596adcc774c36b070e69ec90.jpg","fDirector":"Larry A. McLean","fPerformer":" Amber Frank, Mason Dye, Dylan Sprayberry","fShowtime":"2017-06-02","fScore":0.0,"fPricetagid":"0","fPricetagname":"免费电影","fIntime":"2017-06-02 12:08:34","fShow":1,"fLookct":1,"fMakelookct":15,"fGoodct":2,"fMakegoodct":25,"fCollect":2,"fMakecollect":0,"fPlayct":17,"fMakepalyct":5,"fSharect":1,"fMakesharect":null,"fBuyct":0,"fCommentct":4,"fSourceurl":null,"fCountryname":"美国","fFilmtypename":"奇幻","fImpression":null},{"fId":"594c95065bc42d07a03f1fac","fName":"大婴儿","fFilmtype":"1100010000000000000","fYear":2015,"fCountry":4,"fKeyword":"大婴儿","fPhoto":"http://119.10.70.142:9080/Images/upload/videoPhoto/595a887337ca1d108069af16.png","fPhotow":"http://101.201.122.79:8083/Images/upload/videoPhoto/596adcb874c36b070e69ec8f.jpg","fDirector":"Stephen Langford","fPerformer":"Maureen McCormick, Andrew Lawrence, Ken Davitian","fShowtime":"2015-12-12","fScore":0.0,"fPricetagid":"1","fPricetagname":"2元电影","fIntime":"2017-06-23 12:43:35","fShow":1,"fLookct":0,"fMakelookct":11,"fGoodct":0,"fMakegoodct":12,"fCollect":1,"fMakecollect":13,"fPlayct":11,"fMakepalyct":15,"fSharect":0,"fMakesharect":null,"fBuyct":0,"fCommentct":4,"fSourceurl":null,"fCountryname":"美国","fFilmtypename":"喜剧/爱情/剧情","fImpression":"印象"},{"fId":"594cacc75bc42d07a0aa541b","fName":"正义","fFilmtype":"1100000000000000000","fYear":2016,"fCountry":4,"fKeyword":"正义","fPhoto":"http://119.10.70.142:9080/Images/upload/videoPhoto/595a87a137ca1d108069af14.png","fPhotow":"http://101.201.122.79:8083/Images/upload/videoPhoto/596adc9d74c36b070e69ec8d.jpg","fDirector":"Richard Gabai","fPerformer":" Stephen Lang, Jackson Rathbone, Jamie-Lynn Sigler ","fShowtime":"2016-12-12","fScore":0.0,"fPricetagid":"0","fPricetagname":"免费电影","fIntime":"2017-06-23 14:24:45","fShow":1,"fLookct":0,"fMakelookct":11,"fGoodct":0,"fMakegoodct":12,"fCollect":0,"fMakecollect":13,"fPlayct":4,"fMakepalyct":15,"fSharect":0,"fMakesharect":null,"fBuyct":0,"fCommentct":0,"fSourceurl":null,"fCountryname":"美国","fFilmtypename":"喜剧/爱情","fImpression":"印象"}]},"allcount":0}
                var videoList = data.result;
                if (videoList && videoList.length > 0) {
                    var _html = '';
                    $.each(videoList,function(index,item){

                        _html+='<span class="recommend-tag" onclick="ClickKeyword(\''+item.fKeyword+'\')">'+item.fKeyword+'</span>';
                    });
                    $('#div_hotsearch').html(_html);
                }
                else{
                    $('#div_hotsearch').html('没有数据！');
                }

            }
        }
    });

}

function ClickKeyword(text) {
    filmObject.pno=1;
    $('#searchText').val(text)
    filmObject.text=text;
    //$(".search-btn").click();
}

function  LoadSearchVideos() {

    $('.no-result').hide()

    $.ajax({
        type: 'get',
        url:
        '/api/film/getfilmlist?name='+filmObject.text+'&filmtype=&pno='+filmObject.pno+'&pagesize=' +
        ''+filmObject.pagesize+'&allcount=-1',
        dataType: 'json',
        success: function(data){
            if (mortise_layout.ValidataResult(data)) {
                //{"code":"OperateOk","errorMsg":"","result":{"list":[{"fId":"594cabc05bc42d07a0aa541a","fName":"一个钓鱼的故事","fFilmtype":"1000010100000000000","fYear":2016,"fCountry":12,"fKeyword":"一个钓鱼的故事","fPhoto":"http://119.10.70.142:9080/Images/upload/videoPhoto/595a87fe37ca1d108069af15.png","fPhotow":"http://101.201.122.79:8083/Images/upload/videoPhoto/596adca774c36b070e69ec8e.jpg","fDirector":"Matt Birman","fPerformer":"Eddie McClintock, Jayne Heitmeyer, Jordyn Negri ","fShowtime":"2016-12-12","fScore":0.0,"fPricetagid":"0","fPricetagname":"免费电影","fIntime":"2017-06-23 14:20:23","fShow":1,"fLookct":0,"fMakelookct":11,"fGoodct":0,"fMakegoodct":12,"fCollect":2,"fMakecollect":13,"fPlayct":132,"fMakepalyct":15,"fSharect":0,"fMakesharect":null,"fBuyct":0,"fCommentct":22,"fSourceurl":null,"fCountryname":"加拿大","fFilmtypename":"喜剧/剧情/奇幻","fImpression":"印象"},{"fId":"5930e4cd1c886e2dc0d45342","fName":"末世迷踪：下一代","fFilmtype":"0000000100000000000","fYear":2016,"fCountry":4,"fKeyword":"末世迷踪：下一代","fPhoto":"http://119.10.70.142:9080/Images/upload/videoPhoto/595a88f137ca1d108069af17.png","fPhotow":"http://101.201.122.79:8083/Images/upload/videoPhoto/596adcc774c36b070e69ec90.jpg","fDirector":"Larry A. McLean","fPerformer":" Amber Frank, Mason Dye, Dylan Sprayberry","fShowtime":"2017-06-02","fScore":0.0,"fPricetagid":"0","fPricetagname":"免费电影","fIntime":"2017-06-02 12:08:34","fShow":1,"fLookct":1,"fMakelookct":15,"fGoodct":2,"fMakegoodct":25,"fCollect":2,"fMakecollect":0,"fPlayct":17,"fMakepalyct":5,"fSharect":1,"fMakesharect":null,"fBuyct":0,"fCommentct":4,"fSourceurl":null,"fCountryname":"美国","fFilmtypename":"奇幻","fImpression":null},{"fId":"594c95065bc42d07a03f1fac","fName":"大婴儿","fFilmtype":"1100010000000000000","fYear":2015,"fCountry":4,"fKeyword":"大婴儿","fPhoto":"http://119.10.70.142:9080/Images/upload/videoPhoto/595a887337ca1d108069af16.png","fPhotow":"http://101.201.122.79:8083/Images/upload/videoPhoto/596adcb874c36b070e69ec8f.jpg","fDirector":"Stephen Langford","fPerformer":"Maureen McCormick, Andrew Lawrence, Ken Davitian","fShowtime":"2015-12-12","fScore":0.0,"fPricetagid":"1","fPricetagname":"2元电影","fIntime":"2017-06-23 12:43:35","fShow":1,"fLookct":0,"fMakelookct":11,"fGoodct":0,"fMakegoodct":12,"fCollect":1,"fMakecollect":13,"fPlayct":11,"fMakepalyct":15,"fSharect":0,"fMakesharect":null,"fBuyct":0,"fCommentct":4,"fSourceurl":null,"fCountryname":"美国","fFilmtypename":"喜剧/爱情/剧情","fImpression":"印象"},{"fId":"594cacc75bc42d07a0aa541b","fName":"正义","fFilmtype":"1100000000000000000","fYear":2016,"fCountry":4,"fKeyword":"正义","fPhoto":"http://119.10.70.142:9080/Images/upload/videoPhoto/595a87a137ca1d108069af14.png","fPhotow":"http://101.201.122.79:8083/Images/upload/videoPhoto/596adc9d74c36b070e69ec8d.jpg","fDirector":"Richard Gabai","fPerformer":" Stephen Lang, Jackson Rathbone, Jamie-Lynn Sigler ","fShowtime":"2016-12-12","fScore":0.0,"fPricetagid":"0","fPricetagname":"免费电影","fIntime":"2017-06-23 14:24:45","fShow":1,"fLookct":0,"fMakelookct":11,"fGoodct":0,"fMakegoodct":12,"fCollect":0,"fMakecollect":13,"fPlayct":4,"fMakepalyct":15,"fSharect":0,"fMakesharect":null,"fBuyct":0,"fCommentct":0,"fSourceurl":null,"fCountryname":"美国","fFilmtypename":"喜剧/爱情","fImpression":"印象"}]},"allcount":0}
                var videoList = data.result.list;
                var dataCount=data.result.count;
                if (videoList && videoList.length > 0) {
                    var _html = '';
                    $.each(videoList,function(index,item){
                        // _html+='<span class="sr-list">'+
                        //     '<span class="list-img"><img src="'+item.fPhoto+'"></span>'+
                        //     '<span class="list-info">'+
                        //     '<div class="info-title">'+item.fName+'</div>'+
                        //     '<div class="info-des">'+
                        //     item.fKeyword+
                        //     '</div>'+
                        //     '<div class="play-btn" onclick="GoToVideoInfo(\''+item["fId"] +'\')"> 马上观看</div>'+
                        //     '</span>'+
                        //     '</span>';
                        _html+='<span class="sr-list" onclick="GoToVideoInfo(\''+item.fId+'\')">'+
                        '<span class="list-img"><img src="'+item.fPhoto+'"></span>'+
                        '<span class="list-info">'+
                        '<div class="info-title">'+item.fName+'</div>'+
                        '<div class="info-des">'+
                            item.fKeyword+
                        '</div>'+
                        '<div class="info-other">'+
                        ' <p>'+item.fYear+'年上映 · '+item.fCountryname+'</p>'+
                        '<p>'+item.fFilmtypename+'</p>'+
                        '</div>'+
                        '</span>'+
                        '<div class="list-source">'+item.fScore+'</div>'+
                        '   </span>';
                    });
                    if(filmObject.pno==1){
                        $('#ul_comment').html(_html);
                    }
                    else{
                        $('#ul_comment').append(_html);
                    }
                    if (dataCount>( filmObject.pno)* filmObject.pagesize){
                        $('#div_commentfoot').html('<span class="get-more-data"  style="cursor:pointer" onclick="loadMore()">点击加载更多...</span>');
                    }
                    else{
                        //over
                        $('#div_commentfoot').html('<span class="get-more-data" >没有数据了...</span>');
                    }

                }
                else{
                  	$('.no-result').show();
                }

            }
        }
    });

}
function loadMore() {
    filmObject.pno++;
    LoadSearchVideos();
}